package com.zygh.policeasset.mapper;

import com.zygh.policeasset.pojo.Contract;
import com.zygh.policeasset.pojo.Project;
import com.zygh.policeasset.pojo.ProjectNameType;
import com.zygh.policeasset.pojo.Section;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/mapper/ContractMapper.class */
public interface ContractMapper {
    @Select({"<script>", "select t.*,cp.company_name,p.name as project_name,s.section_name," +
            "cy.type as type,st.audit_amount,af.app_status,af.approval_steps_id as approvalStepsId,u.name as userName from contract t " +
            "left join section s on t.section_id = s.id left join project p on t.project_no = p.project_no " +
            "left join audit_flow af on t.flow_no = af.flow_no left join user u on af.applicant = u.id " +
            "left join category cy on p.category = cy.id left join company cp on t.company_id = cp.id " +
            "left join settlement st on t.section_id = st.section_id  and t.project_no = st.project_no " +
            "<where>" +
            "<if test='name != null and name.length &gt; 0'> and p.name like '%${name}%' </if>" +
            "<if test='category != null and category &gt; 0'>and p.category=#{category} </if>" +
            "<if test='companyId != null and companyId != 0 '> and t.company_id = #{companyId} </if>" +
            "<if test='time1 != null and time2 != null and time1.length &gt; 0 and time2.length &gt; 0'> and t.confirm_time between #{time1} and  #{time2} </if>" +
            "<if test='userId != null '> and af.applicant=#{userId} </if>" +
            "<if test=' status != null'> and af.app_status = #{status} </if>" +
            "</where>order by t.id desc </script>"})
    @Results({@Result(property = "projectNo", column = "project_no"),
            @Result(property = "projectName", column = "project_name"),
            @Result(property = "sectionId", column = "section_id"),
            @Result(property = "companyId", column = "company_id"),
            @Result(property = "companyName", column = "company_name"),
            @Result(property = "contractNo", column = "contract_no"),
            @Result(property = "timeInterval", column = "time_interval"),
            @Result(property = "startTime", column = "start_time"),
            @Result(property = "endTime", column = "end_time"),
            @Result(property = "confirmTime", column = "confirm_time"),
            @Result(property = "paymentMethod", column = "payment_method"),
            @Result(property = "sectionName", column = "section_name"),
            @Result(property = "expectedInvisibleAmount", column = "expected_invisible_amount"),
            @Result(property = "expectedFixedAmount", column = "expected_fixed_amount"),
            @Result(property = "companyDesign", column = "company_design"),
            @Result(property = "auditAmount", column = "audit_amount"),
            @Result(property = "flowNo", column = "flow_no"),
            @Result(property = "appStatus", column = "app_status")})
    List<Contract> findAll(@Param("name") String name,
                           @Param("status") Integer status,
                           @Param("companyId") Integer companyId,
                           @Param("time1") String time1,
                           @Param("time2") String time2,
                           @Param("category") Integer category,
                           @Param("userId") Integer userId);

    @Select({"select count(*) from contract t  where app_status = 1"})
    Integer findCount();

    @Select({"select c.*,cp.company_name,p.name as project_name,pr.status as status,pr.opinion as opinion from contract c left join processrecord pr on c.id=pr.project_id and pr.process_name='contract' left join project p on c.project_no = p.project_no left join company cp on c.company_id = cp.id where pr.status=#{status} order by c.id desc "})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "project_name"), @Result(property = "sectionId", column = "section_id"), @Result(property = "companyId", column = "company_id"), @Result(property = "companyName", column = "company_name"), @Result(property = "contractNo", column = "contract_no"), @Result(property = "timeInterval", column = "time_interval"), @Result(property = "startTime", column = "start_time"), @Result(property = "endTime", column = "end_time"), @Result(property = "confirmTime", column = "confirm_time"), @Result(property = "paymentMethod", column = "payment_method"), @Result(property = "expectedInvisibleAmount", column = "expected_invisible_amount"), @Result(property = "expectedFixedAmount", column = "expected_fixed_amount"), @Result(property = "companyDesign", column = "company_design")})
    List<Contract> findByStatus(int i);

    @Select({"select c.*,cp.company_name,p.name as project_name,s.section_name,af.app_status from contract c left join section s on c.section_id=s.id left join project p on c.project_no = p.project_no left join company cp on c.company_id = cp.id left join audit_flow af on c.flow_no = af.flow_no where c.project_no = #{no} order by c.id desc "})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "project_name"), @Result(property = "sectionId", column = "section_id"), @Result(property = "sectionName", column = "section_name"), @Result(property = "companyId", column = "company_id"), @Result(property = "companyName", column = "company_name"), @Result(property = "contractNo", column = "contract_no"), @Result(property = "timeInterval", column = "time_interval"), @Result(property = "startTime", column = "start_time"), @Result(property = "endTime", column = "end_time"), @Result(property = "confirmTime", column = "confirm_time"), @Result(property = "paymentMethod", column = "payment_method"), @Result(property = "expectedInvisibleAmount", column = "expected_invisible_amount"), @Result(property = "expectedFixedAmount", column = "expected_fixed_amount"), @Result(property = "companyDesign", column = "company_design"), @Result(property = "appStatus", column = "app_status")})
    List<Contract> findByProject(String str);

    @Select({"SELECT  p.*,cy.type  FROM  tender t  " +
            "LEFT JOIN audit_flow af ON t.flow_no = af.flow_no  " +
            "LEFT JOIN section s ON s.tender_id = t.id  " +
            "LEFT JOIN project p ON t.project_no = p.project_no  " +
            "LEFT JOIN category cy ON p.category = cy.id  " +
            "LEFT JOIN contract c ON s.id = c.section_id  " +
            "WHERE  af.app_status = 2 and af.table_type = 'tender'  " +
            "AND c.project_no IS NULL  and p.pid is not null " +
            "GROUP BY  p.project_no  order by t.id desc"})
    @Results({@Result(property = "projectNo", column = "project_no"),
            @Result(property = "commissionNo", column = "commission_no"),
            @Result(property = "companyApply", column = "company_apply"),
            @Result(property = "capitalSource", column = "capital_source"),
            @Result(property = "projectBase", column = "project_base"),
            @Result(property = "startDatetime", column = "start_datetime"),
            @Result(property = "expectedInvisibleAmount", column = "expected_invisible_amount"),
            @Result(property = "expectedFixedAmount", column = "expected_fixed_amount"),
            @Result(property = "companyDesign", column = "company_design")})
    List<Project> getProject();

    @Select({"SELECT s.*,p.name as project_name FROM section s left join tender t on s.tender_id = t.id LEFT JOIN audit_flow af ON t.flow_no = af.flow_no left join contract c on s.id = c.section_id left join project p on s.project_no = p.project_no WHERE af.app_status = 2 and af.table_type = 'tender' and c.section_id is null and t.project_no = #{projectNo} ORDER BY s.id DESC "})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "project_name"), @Result(property = "tenderId", column = "tender_id"), @Result(property = "sectionName", column = "section_name"), @Result(property = "sectionTime", column = "section_time"), @Result(property = "assectStatus", column = "assect_status"), @Result(property = "expectedInvisibleAmount", column = "expected_invisible_amount"), @Result(property = "expectedFixedAmount", column = "expected_fixed_amount"), @Result(property = "companyDesign", column = "company_design")})
    List<Section> getAdd(String str);

    @Insert({"insert into contract (project_no,section_id,name,company_id,contract_no," +
            "time_interval,start_time,end_time,confirm_time,money,payment_method," +
            "expected_fixed_amount,expected_invisible_amount,company_design,flow_no) " +
            "values (#{projectNo},#{sectionId},#{name},#{companyId},#{contractNo}," +
            "#{timeInterval},#{startTime},#{endTime},#{confirmTime},#{money},#{paymentMethod}," +
            "#{expectedFixedAmount},#{expectedInvisibleAmount},#{companyDesign},#{flowNo})"})
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer add(Contract contract);

    @Update({"update contract set project_no=#{projectNo},section_id=#{sectionId},name=#{name},company_id=#{companyId}," +
            "contract_no=#{contractNo},time_interval=#{timeInterval},start_time=#{startTime},end_time=#{endTime}," +
            "confirm_time=#{confirmTime},money=#{money},payment_method=#{paymentMethod}," +
            "expected_fixed_amount=#{expectedFixedAmount},expected_invisible_amount=#{expectedInvisibleAmount}, " +
            "company_design=#{companyDesign} where id=#{id}"})
    Integer update(Contract contract);

    @Delete({"delete from contract where id=#{id}"})
    Integer remove(int i);

    @Update({"update contract set app_status=#{status} where id=#{id}"})
    Integer updateStatus(int i, int i2);

    @Select({"SELECT DISTINCT p.name,p.project_no  FROM contract c " +
            "LEFT JOIN  project p ON c.project_no= p.project_no " +
            "left join audit_flow a on c.flow_no=a.flow_no " +
            "WHERE a.app_status = 2 "})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "name")})
    List<ProjectNameType> selectBytype();

    @Select({"SELECT s.section_name  FROM contract c LEFT JOIN  section s ON c.section_id= s.id WHERE c.project_no = #{projectNo} "})
    @Results({@Result(property = "sectionName", column = "section_name")})
    List<ProjectNameType> findSectionByType(@Param("projectNo") String str);

    @Select({"<script> SELECT t.*,p.name as project_name,s.`section_name`,co.company_name  FROM contract t LEFT JOIN  project p ON t.project_no= p.project_no LEFT JOIN category c ON p.category = c.id  LEFT JOIN `section` s ON  t.`section_id`=s.`id` LEFT JOIN `company` co ON  t.`company_id`=co.`id` left join audit_flow af on t.flow_no = af.flow_no <where>af.app_status = 2 and p.category=#{id} <if test='name != null and name.length &gt; 0'> and p.name like '%${name}%' </if><if test='companyId != null and companyId != 0'> and t.company_id = #{companyId} </if><if test='time1 != null and time2 != null and time1.length &gt; 0 and time2.length &gt; 0'> and t.confirm_time between #{time1} and  #{time2} </if></where></script> "})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "project_name"), @Result(property = "sectionId", column = "section_id"), @Result(property = "companyId", column = "company_id"), @Result(property = "companyName", column = "company_name"), @Result(property = "contractNo", column = "contract_no"), @Result(property = "timeInterval", column = "time_interval"), @Result(property = "startTime", column = "start_time"), @Result(property = "endTime", column = "end_time"), @Result(property = "confirmTime", column = "confirm_time"), @Result(property = "paymentMethod", column = "payment_method"), @Result(property = "sectionName", column = "section_name"), @Result(property = "expectedInvisibleAmount", column = "expected_invisible_amount"), @Result(property = "expectedFixedAmount", column = "expected_fixed_amount"), @Result(property = "companyDesign", column = "company_design")})
    List<Contract> toExcel(Integer num, String str, String str2, String str3, String str4);

    @Select({"<script>", "select t.*,cp.company_name,p.name as project_name,s.section_name,cy.type as type,st.audit_amount,af.app_status,af.approval_steps_id as approvalStepsId,u.name as userName from contract t left join section s on t.section_id = s.id left join project p on t.project_no = p.project_no left join category cy on p.category = cy.id left join company cp on t.company_id = cp.id left join settlement st on t.section_id = st.section_id  left join audit_flow af on t.flow_no = af.flow_no left join user u on af.applicant = u.id and t.project_no = st.project_no<where><if test='id != null'> and t.id = #{id} </if></where></script>"})
    @Results({@Result(property = "projectNo", column = "project_no"), @Result(property = "projectName", column = "project_name"), @Result(property = "sectionId", column = "section_id"), @Result(property = "companyId", column = "company_id"), @Result(property = "companyName", column = "company_name"), @Result(property = "contractNo", column = "contract_no"), @Result(property = "timeInterval", column = "time_interval"), @Result(property = "startTime", column = "start_time"), @Result(property = "endTime", column = "end_time"), @Result(property = "confirmTime", column = "confirm_time"), @Result(property = "paymentMethod", column = "payment_method"), @Result(property = "sectionName", column = "section_name"), @Result(property = "expectedInvisibleAmount", column = "expected_invisible_amount"), @Result(property = "expectedFixedAmount", column = "expected_fixed_amount"), @Result(property = "companyDesign", column = "company_design"), @Result(property = "auditAmount", column = "audit_amount"), @Result(property = "appStatus", column = "app_status"), @Result(property = "flowNo", column = "flow_no")})
    Contract findById(@Param("id") Integer num);

}